package top.btcmarket.auth.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.stereotype.Service;

import top.btcmarket.auth.entity.Resources;
import top.btcmarket.auth.mapper.ResourcesRepository;
import top.btcmarket.auth.service.ResourcesService;


@Service
public class ResourcesServiceImpl implements ResourcesService {

    @Autowired
    private ResourcesRepository resourcesRepository;

	@Override
	public Resources findById(int id) {
		// TODO Auto-generated method stub
		return resourcesRepository.findById(id);
	}

	@Override
	public List<Resources> findAll() {
		// TODO Auto-generated method stub
		return resourcesRepository.findAll();
	}

	@Override
	public void save(Resources res) {
		// TODO Auto-generated method stub
		 Example<Resources> ex = Example.of(res); 
		 if(resourcesRepository.findOne(ex)==null){
			 resourcesRepository.save(res);
		 }
	}

	@Override
	public void saveList(List<Resources> res) {
		// TODO Auto-generated method stub
		
		for (Resources resources : res) {
			save(resources);
		}
		
//		resourcesRepository.save(res);
	}





}
